﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Util;

namespace Api
{
    /// <summary>
    /// Speech recognizer that works with audio resources.
    ///
    /// @see LiveSpeechRecognizer live speech recognizer
    /// </summary>
    public class StreamSpeechRecognizer : AbstractSpeechRecognizer
    {
        /// <summary>
        /// Constructs new stream recognizer.
        /// </summary>
        /// <param name="configuration">configuration</param>
        public StreamSpeechRecognizer(Configuration configuration)
            :base(configuration)
        {
            
        }

        public void startRecognition(FileStream stream) 
        {
            startRecognition(stream, TimeFrame.INFINITE);
        }

        public void startRecognition(String stream)
        {
            recognizer.allocate();
            context.setSpeechSource(stream);
        }

        /// <summary>
        /// Starts recognition process.
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="timeFrame"></param>
        public void startRecognition(FileStream stream, TimeFrame timeFrame) 
        {
            recognizer.allocate();
            context.setSpeechSource(stream, timeFrame);
        }

        /// <summary>
        /// Stops recognition process.
        /// </summary>
        public void stopRecognition() 
        {
            recognizer.deallocate();
        }
    }
}
